<template>
  <div>
    <Row class="header">
      <img :src="$store.state.app.logoImg" class="logo"/>
    </Row>
  </div>
</template>

<script>
import {getBaseSite} from "@/api/common.js";
import {getStore} from "@/libs/storage";

export default {
  // name: "header",
  data() {
    return {
      storeSideLogo: "",
    };
  },
  methods: {
    init() {
      this.storeSideLogo = require("@/assets/logo" + getStore("storeId") + ".png");
      if (
        !localStorage.getItem("sellersiteName") ||
        !localStorage.getItem("sellerlogoImg") ||
        !localStorage.getItem("sellerIconImg") ||
        !localStorage.getItem("seller_expiration_time")
      ) {
        this.getSite();
      } else {
        // 如果缓存过期，则获取最新的信息
        if (new Date() > localStorage.getItem("seller_expiration_time")) {
          this.getSite();

        } else {
          window.document.title = localStorage.getItem("sellersiteName");
          //動态获取icon
          let link =
            document.querySelector("link[rel*='icon']") ||
            document.createElement("link");
          link.type = "image/x-icon";
          link.href = localStorage.getItem("sellerIconImg");
          link.rel = "shortcut icon";
          document.getElementsByTagName("head")[0].appendChild(link);
        }
      }
    },
    getSite() {
      //获取基本站点信息
      getBaseSite().then((res) => {
        if (res.success && res.result.settingValue) {
          let data = JSON.parse(res.result.settingValue);
          // 过期時間
          var expirationTime = new Date().setHours(new Date().getHours() + 1);
          // 存放过期時間
          localStorage.setItem("seller_expiration_time", expirationTime);
          // 存放信息
          // localStorage.setItem("sellersiteName", data.siteName);
          localStorage.setItem("sellerlogoImg", data.storeSideLogo);
          localStorage.setItem("sellerIconImg", data.storeSideIcon);
          console.log(data, "datadadada");
          var config= require('@/config/title'+window.localStorage.getItem("storeId")+'.js');
          window.document.title = config.title;
          localStorage.setItem('sellersiteName', config.title);
          // window.document.title = data.siteName;
          //動态获取icon
          let link =
            document.querySelector("link[rel*='icon']") ||
            document.createElement("link");
          link.type = "image/x-icon";
          link.href = data.storeSideIcon;
          link.rel = "shortcut icon";
          document.getElementsByTagName("head")[0].appendChild(link);
        }
      });
    },
  },

  mounted() {
    this.init();
  },
};
</script>

<style lang="scss" scoped>
.header {
  margin-bottom: 6vh;
  align-items: center;
  display: flex;
  justify-content: center !important;
}

.logo {
  width: 440px;
  height: 158px;
}
</style>
